package dst1;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import dst1.model.Environment;
import dst1.model.Job;

public class Main {

	private EntityManagerFactory emf;
	private EntityManager em;
	private String PERSISTANCE_UNIT_NAME = "grid";
	private Main() {
		super();
	}

	public static void main(String[] args) {
		dst01();
		dst02a();
		dst02b();
		dst02c();
		dst03();
		dst04a();
		dst04b();
		dst04c();
		dst04d();
	}

	public static void dst01() {
		Main main = new Main();
		main.initEntityManager();
		main.create();
		main.read();
		main.closeEntityManager();
	}

	public static void dst02a() {

	}

	public static void dst02b() {

	}

	public static void dst02c() {

	}

	public static void dst03() {

	}

	public static void dst04a() {

	}

	public static void dst04b() {

	}

	public static void dst04c() {

	}

	public static void dst04d() {

	}
	
	private void initEntityManager(){
		emf = Persistence.createEntityManagerFactory("grid");
		em = emf.createEntityManager();
	}
	
	private void create(){
		em.getTransaction().begin();
		Environment environment = new Environment();
		environment.setWorkflow("workflow1");
		em.persist(environment);

		Job job = new Job();
		job.setExecutionTime(100);
		job.setNumCPUs(5);
		//job.setEnvironment(environment);
		
		em.flush();
		em.persist(job);		
		
		em.getTransaction().commit();
	}
	
	private void read(){
		
		System.out.println("Query returned: " );
	}
	
	private void closeEntityManager(){
		em.close();
		emf.close();	
	}
}
